#include <stdio.h>
#include "NCScript.h"
#include "NClex.h"
#include "NCSyn.h"
#include "NCapi.h"

int print(NC *nc){
	switch(NC_GetType(nc)){
		case VLTP_INT:
			printf("%d",NC_Pop_int(nc));
		break;
		case VLTP_DOUBLE:
			printf("%f",NC_Pop_double(nc));
		break;
		case VLTP_PCHAR:
			printf(NC_Pop_pchar(nc));
		break;
	}

	return 0;
}

void safety_gets(char* a,int b){
	int t,i=0;
	fflush(stdin);
	while((t=getchar())!='\n'){
		if(++i<b){
			*a++=(char)t;
		}
	}
	*a=0;
}


int main(){
	char scr[512];
	int i;
	NC t;
	value v;
	t.rub=RUB_Init();
	safety_gets(&scr[0],sizeof(scr));
	t.line=1;
	t.val=malloc(sizeof(valist));
	t.sym=malloc(sizeof(valist));
	t.stack=malloc(sizeof(valist));
	t.val->next=0;
	t.sym->next=0;
	t.stack->next=0;
	t.funreg=0;
	t.symnum=0;
	//while(1){
	NC_RegFunction(&t,"print",&print);
	t.s=&scr[0];
	lex(&t);
	TheEnd(&t);
	/*t.val=pop(t.val,&v);
	
	switch(v.type){
		case VLTP_INT:
			printf("=%d",v.u.i);
		break;
		case VLTP_DOUBLE:
			printf("=%f",v.u.d);
		break;
	}
	*/

	//}
	return 0;
}